package net.lesscoding.group;

import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * @author eleven
 * @date 2024/10/23 16:05
 * @apiNote
 */
@Slf4j
public class EventLoopTest {

    @Test
    public void eventLoopTest() throws InterruptedException {
        // 1. 创建EventLoopGroup IO事件，普通任务和定时任务
        EventLoopGroup group = new NioEventLoopGroup(2);
        // 默认的是EventLoopGroup
        //EventLoopGroup defaultGroup = new DefaultEventLoopGroup();
        // 2. 获取下一个EventLoop
        System.out.println(group.next());
        System.out.println(group.next());
        System.out.println(group.next());

        // 普通任务
        group.next().submit(() -> log.info("Sub Thread run"));
        // 定时任务 一秒后执行
        group.next().scheduleAtFixedRate(() -> log.info(" Schedule Sub Thread run"), 0, 1, TimeUnit.SECONDS);
        log.info("Main Thread run ");
        CountDownLatch countDownLatch = new CountDownLatch(1);
        countDownLatch.await();
    }
}
